#include <iostream>
#include <unistd.h>

using namespace std;

void Test()
{
    cout << "我是一个父进程" << endl;

    pid_t pid = fork();
    
    if(pid < 0)
    {
        cout << "创建子进程失败" << endl;
    }
    else if(pid == 0)
    {
        while(1)
        {
            cout << "我是子进程，pid：" << getpid() << "ppid:" << getppid() << endl;
            sleep(1);
        }
    }
    else 
    {
        while(1)
        {
            cout << "我是子进程，pid：" << getpid() << "ppid:" << getppid() << endl;
            sleep(1);
        }
    }
}

int main()
{
    Test();
    return 0;
}
